package com.weavernorth.create;


import com.weaver.general.BaseBean;


import com.weavernorth.util.CallBack;

import com.weavernorth.util.Logger4jUtil;
import com.weavernorth.util.StoreServer;

import org.apache.log4j.Logger;
import weaver.conn.RecordSet;

import weaver.general.Util;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import weaver.workflow.webservices.*;


public class CreateResumeFlow {

//    private static Log log = org.apache.commons.logging.LogFactory.getLog(CreateResumeFlow.class.getName());
 private  Logger log = Logger4jUtil.getLoggerByName("/Timmer/CreateResumeFlow/");
    public void createResumeFlow(JSONObject data) {

        RecordSet rsFive = new RecordSet();
        RecordSet rsFour = new RecordSet();
        RecordSet rsUpdate = new RecordSet();
        RecordSet rsHr = new RecordSet();
        RecordSet rsHrTwo = new RecordSet();
        RecordSet rsHrThree = new RecordSet();
        RecordSet rsHrFour = new RecordSet();
        RecordSet rsHk = new RecordSet();
        RecordSet rsResume = new RecordSet();
        StringBuffer sbuffApplyids = new StringBuffer();
        log.info("创建流程");
        BaseBean bb = new BaseBean();

        //用于将返回值格式化为JSONArray类型
        JSONArray resumeArray = new JSONArray();
        //创建主表和明细表的对象和数组
        JSONObject personalJson = new JSONObject();
        JSONArray educationJson = new JSONArray();
        JSONArray workingJsonarry = new JSONArray();
        JSONArray familyJsonarry = new JSONArray();
        //获取简历的基础信息


        //如果建立信息不为null时
        if (data.get("resume") != null) {
            //返回值的最外层数据转为JSON数组
            resumeArray = JSONArray.fromObject(data.get("resume"));
        }
        log.info("简历个数：" + resumeArray.size());
        //返回值含有多个简历信息，做for循环创建多个流程
        for (int j = 0; j < resumeArray.size(); j++) {
            //返回值数组中循环取jsonobject
            JSONObject resumeJson = JSONObject.fromObject(resumeArray.get(j));
            log.info("简历json:"+resumeJson.toString());
            //获取简历id
            String strApplyId = Util.null2String(resumeJson.get("applyId"));
            log.info("简历id" + strApplyId);
            //查询此简历id是否已经创建过入职流程
            String strResumeSql = "select * from uf_hd  where jlid = '" + strApplyId + "' and lcid >'0'";
            log.info("查询简历id是否创建过流程的sql" + strResumeSql);
            rsResume.executeQuery(strResumeSql);
            //此简历id未被创建过入职流程
            if (!rsResume.next()) {
                try {
                log.info("此简历id未被创建过流程2");
                //在循环得到的jsonobject中继续取jsonobject, 简历信息
                String resumeContent = Util.null2String(resumeJson.get("resumeContent"));
                JSONObject resumeContents = JSONObject.fromObject(resumeContent);

                //循环中获取创建人hr
                String basicInfo = Util.null2String(resumeJson.get("basicInfo"));
                JSONObject basicInfos = JSONObject.fromObject(basicInfo);
                log.info("存放创建人hr的json" + basicInfos);

                //在继续取到的Jsonobject中获取主表信息
                String personalInformation = Util.null2String(resumeContents.get("personalInformation"));
                personalJson = JSONObject.fromObject(personalInformation);

                //在继续取到的Jsonobject中获取明细表信息1
                //判断是否含有明细表1
                if (resumeContents.containsKey("educationBackground")) {
                    String educationBackground = Util.null2String(resumeContents.get("educationBackground"));
                    educationJson = JSONArray.fromObject(educationBackground);
                }
                //在继续取到的Jsonobject中获取明细表信息2
                //判断是否含有明细表2 工作经历
                if (resumeContents.containsKey("workingExperience")) {
                    String workingExperience = Util.null2String(resumeContents.get("workingExperience"));
                    workingJsonarry = JSONArray.fromObject(workingExperience);
                }
                //在继续取到的Jsonobject中获取明细表信息3 ，家庭成员
                //判断是否含有明细表3
                if (resumeContents.containsKey("familyRelationship")) {
                    String familyRelationship = Util.null2String(resumeContents.get("familyRelationship"));
                    familyJsonarry = JSONArray.fromObject(familyRelationship);
                }

                //存放主表字段的数组 “新增税收居民类型
                WorkflowRequestTableField[] wrti = new WorkflowRequestTableField[29];
                //添加姓名字段
                //从JSONobject中获取字段信息
                String strXm = Util.null2String(personalJson.getString("name"));
                log.info("姓名：" + strXm);
                wrti[0] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[0].setFieldName("xm");
                //赋值
                wrti[0].setFieldValue(Util.null2String(strXm));
                wrti[0].setView(true);
                wrti[0].setEdit(true);
                wrti[0].setFieldOrder(0);
                wrti[0].setMand(false);

                //添加性别字段
                //从JSONobject中获取字段信息
                String strXb = Util.null2String(personalJson.getString("gender"));
                wrti[1] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[1].setFieldName("xb");
                log.info("性别："+strXb);
                //赋值
                //码表关系转换
                if ("0/599/604".equals(strXb)) {
                    //String strBoy = bb.getPropValue("porturl", "boy");
                    log.info("boy:" + 0);
                    wrti[1].setFieldValue("0");
                }else{
               // if ("0/599/605".equals(strXb)) {
                    //String strGirl = bb.getPropValue("porturl", "girl");
                    log.info("girl:" + 1);
                    wrti[1].setFieldValue("1");
                }
//                if ("".equals(strXb)) {
//                    wrti[1].setFieldValue(strXb);
//                }
                wrti[1].setView(true);
                wrti[1].setEdit(true);
                wrti[1].setFieldOrder(0);
                wrti[1].setMand(false);


                //添加民族字段
                //从JSONobject中获取字段信息
                String strMz = Util.null2String(personalJson.getString("nation"));
                log.info("民族：" + strMz);
                wrti[2] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[2].setFieldName("mz");
                //赋值
                //码表关系转换
                //查询对应流程显示的民族
                log.info("未在建模表中查询的民族值：" + strMz);
                String strMzCode = "select id,mz from uf_mz where mzdmdy = '" + strMz + "'";
                log.info("查询建模表民族的sql:" + strMzCode);
                log.info("民族码表sql:" + strMzCode);
                RecordSet rsMz = new RecordSet();
                rsMz.execute(strMzCode);
                //如果有值
                if (rsMz.next()) {
                    log.info("码表对应民族:" + Util.null2String(rsMz.getString("mz")));
                    wrti[2].setFieldValue(Util.null2String(Util.null2String(rsMz.getString("id"))));
                }
                if ("".equals(strMz)) {
                    wrti[2].setFieldValue(strMz);
                }
                wrti[2].setView(true);
                wrti[2].setEdit(true);
                wrti[2].setFieldOrder(0);
                wrti[2].setMand(false);

                //添加出生日期字段
                //从JSONobject中获取字段信息
                String strCsrq = personalJson.getString("dateOfBirth");
                log.info("出生日期：" + strCsrq);
                wrti[3] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[3].setFieldName("csrq");
                //赋值
                wrti[3].setFieldValue(Util.null2String(strCsrq));
                wrti[3].setView(true);
                wrti[3].setEdit(true);
                wrti[3].setFieldOrder(0);
                wrti[3].setMand(false);

                //添加籍贯字段
                //从JSONobject中获取字段信息
                String strJg = personalJson.getString("hometown");
                log.info("籍贯：" + strJg);
                wrti[4] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[4].setFieldName("jg");
                //存储拼接后的籍贯代码
                StringBuffer jgSB = new StringBuffer();
                if (strJg != null && !"".equals(strJg) && !"null".equals(strJg)) {
                    //对大易籍贯代码分组并拼接
                    String[] jgSplit = strJg.split("/");
                    jgSB.append(jgSplit[0]);
                    jgSB.append("/");
                    jgSB.append(jgSplit[1]);
                    jgSB.append("/");
                    jgSB.append(jgSplit[2]);

                    String jgStr = jgSB.toString();
                    log.info("未在建模表中查询的籍贯代码：" + jgStr);
                    String jgCode = "select jg  from  uf_jg  where  jgdmdy = '" + jgStr + "'";
                    log.info("查询建模表籍贯的sql：" + jgCode);
                    log.info("籍贯sql:" + jgCode);
                    RecordSet rsJg = new RecordSet();
                    rsJg.execute(jgCode);
                    if (rsJg.next()) {
                        //赋值
                        wrti[4].setFieldValue(Util.null2String(rsJg.getString("jg")));
                    } else {
                        wrti[4].setFieldValue("其他");
                    }
                } else {
                    //赋值
                    wrti[4].setFieldValue(Util.null2String(strJg));
                }
                wrti[4].setView(true);
                wrti[4].setEdit(true);
                wrti[4].setFieldOrder(0);
                wrti[4].setMand(false);

                //添加户口所在地字段
                //从JSONobject中获取字段信息
                String strHkszd = personalJson.getString("originPlace");
                log.info("户口所在地：" + strHkszd);
                wrti[5] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[5].setFieldName("hkszd");
                log.info(strHkszd + "户口所在地");
                //从建模表中查询对应编码
                String strHkSql = "select * from uf_hkszd where dycode ='" + strHkszd + "'";
                rsHk.executeQuery(strHkSql);
                //赋值
                if (rsHk.next()) {
                    wrti[5].setFieldValue(Util.null2String(rsHk.getString("cs")));
                } else {
                    wrti[5].setFieldValue(Util.null2String(strHkszd));
                }
                wrti[5].setView(true);
                wrti[5].setEdit(true);
                wrti[5].setFieldOrder(0);
                wrti[5].setMand(false);

                //添加婚姻状况字段
                //从JSONobject中获取字段信息
                String strHyzk = personalJson.getString("maritalStatus");
                log.info("婚姻状况：" + strHyzk);
                wrti[6] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[6].setFieldName("hyzk");
                log.info(strHyzk + "婚姻状况");
                //根据情况赋值
                if ("0/209/211".equals(strHyzk)) {
                    wrti[6].setFieldValue("0");
                }
                if ("0/209/212".equals(strHyzk)) {
                    wrti[6].setFieldValue("1");
                }
                if ("0/209/52113757".equals(strHyzk)) {
                    wrti[6].setFieldValue("2");
                }
                wrti[6].setView(true);
                wrti[6].setEdit(true);
                wrti[6].setFieldOrder(0);
                wrti[6].setMand(false);

                //添加政治面貌字段
                //从JSONobject中获取字段信息
                String strZzmm = personalJson.getString("politicalStatus");
                log.info("政治面貌：" + strZzmm);
                wrti[7] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[7].setFieldName("zzmm");
                log.info(strZzmm + "政治面貌");
                //赋值
                wrti[7].setFieldValue(Util.null2String(strZzmm));
                wrti[7].setView(true);
                wrti[7].setEdit(true);
                wrti[7].setFieldOrder(0);
                wrti[7].setMand(false);

                //添加个人电话字段
                //从JSONobject中获取字段信息
                String strGrdh = personalJson.getString("mobilePhone");
                log.info("个人电话：" + strGrdh);
                wrti[8] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[8].setFieldName("grdh");
                log.info(strGrdh + "个人电话");
                //赋值
                wrti[8].setFieldValue(Util.null2String(strGrdh));
                wrti[8].setView(true);
                wrti[8].setEdit(true);
                wrti[8].setFieldOrder(0);
                wrti[8].setMand(false);


                //添加现居住地字段
                //从JSONobject中获取字段信息
                String strXjzd = personalJson.getString("currentCity");
                log.info("现居住地：" + strXjzd);
                //查询居住地码表对应
                rsHr.executeQuery("select xjzd from uf_xjzdmb where xjzdbm=?",strXjzd);
                rsHr.next();
                String strXjzdDy=Util.null2String(rsHr.getString("xjzd"));
                wrti[9] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[9].setFieldName("xjzd");
                log.info(strXjzd + "现居住地;"+strXjzdDy);
                //赋值
                wrti[9].setFieldValue(Util.null2String(strXjzdDy));
                wrti[9].setView(true);
                wrti[9].setEdit(true);
                wrti[9].setFieldOrder(0);
                wrti[9].setMand(false);

                //添加图片字段
                //从JSONobject中获取字段信息
                //bb.writeLog(personalJson.get("photo")+"：测试");
                JSONObject strTp = personalJson.getJSONObject("photo");
                //log.info("图片信息:"+strTp+","+strTp.toString()+","+(strTp.size()!=0));
                //调用方法生成对应id
                int intDocId=0;
                if(strTp.size()!=0){
                    intDocId = StoreServer.photoStoreServer(strTp.toString());
                }

                log.info("附件返回的id:" + intDocId);
                wrti[10] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[10].setFieldName("fj");

                //赋值
                wrti[10].setFieldValue(String.valueOf(intDocId));
                wrti[10].setView(true);
                wrti[10].setEdit(true);
                wrti[10].setFieldOrder(0);
                wrti[10].setMand(false);


                //添加户口类型字段
                //从JSONobject中获取字段信息
                //测试
                String strHklx = personalJson.getString("hjxz");
                // String strHklx="null";
                log.info("户口类型：" + strHklx);
                wrti[11] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[11].setFieldName("hklx");
                //赋值
                if (("0/100314/101802").equals(strHklx)) {
                    String strAgro = bb.getPropValue("porturl", "agro");//农业：1
                    log.info("户口类型转码后的值：" + strAgro);
                    wrti[11].setFieldValue(strAgro);
                }
                if (("0/100314/101801").equals(strHklx)) {
                    String strNotagro = bb.getPropValue("porturl", "notagro");
                    log.info("户口类型转码后的值：" + strNotagro);
                    wrti[11].setFieldValue(strNotagro);
                }
                if (("0/100314/101803").equals(strHklx)) {
                    String strOther = bb.getPropValue("porturl", "other");
                    log.info("户口类型转码后的值：" + strOther);
                    wrti[11].setFieldValue(strOther);
                }
                if ("null".equals(strHklx)) {
                    wrti[11].setFieldValue("");
                }
                wrti[11].setView(true);
                wrti[11].setEdit(true);
                wrti[11].setFieldOrder(0);
                wrti[11].setMand(false);

                    //添加证件类型字段
                    log.info("获取证件类型");
                    String strZjlx = Util.null2String(personalJson.getString("iDType"));
                    log.info("证件类型：" + strZjlx);
                    wrti[12] = new WorkflowRequestTableField();
                    //字段在数据库中的字段名
                    wrti[12].setFieldName("zjlx");
                    //赋值
                    if (strZjlx.equals("null")) {
                        wrti[12].setFieldValue(Util.null2String(""));
                    } else {
                        wrti[12].setFieldValue(Util.null2String(strZjlx));
                    }
                    wrti[12].setView(true);
                    wrti[12].setEdit(true);
                    wrti[12].setFieldOrder(0);
                    wrti[12].setMand(false);

                //添加证件号字段
                //从JSONobject中获取字段信息
                log.info("获取证件号");
                String strZjh = Util.null2String(personalJson.getString("iDNUM"));
                log.info("证件号：" + strZjh);
                wrti[13] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[13].setFieldName("zjh");
                //赋值
                if (strZjh.equals("null")) {
                    wrti[13].setFieldValue(Util.null2String(""));
                } else {
                    wrti[13].setFieldValue(Util.null2String(strZjh));
                }
                wrti[13].setView(true);
                wrti[13].setEdit(true);
                wrti[13].setFieldOrder(0);
                wrti[13].setMand(false);

                //添加工作地字段
                //从JSONobject中获取字段信息
                // String strGzd =personalJson.getString("DesiredLocation");
                String strGzd = "null";
                log.info("工作地：" + strGzd);
                wrti[14] = new WorkflowRequestTableField();
                //字段在数据库中的字段名
                wrti[14].setFieldName("gzd");
                log.info(strGzd + "工作地");
                //赋值
                if (strGzd.equals("null")) {
                    wrti[14].setFieldValue(Util.null2String(""));
                } else {
                    wrti[14].setFieldValue(Util.null2String(strGzd));
                }
                wrti[14].setView(true);
                wrti[14].setEdit(true);
                wrti[14].setFieldOrder(0);
                wrti[14].setMand(false);

                //region [添加工资项信息]

                JSONObject jsonGzx = resumeJson.getJSONObject("offerInfo").getJSONObject("expectedAnnualSalaryBeforeTax");
                log.info("工资项信息："+jsonGzx.toString());

                    if (jsonGzx != null && jsonGzx.size() != 0) {
                        log.info("添加工资项信息===》：");
                        String strs1 = Util.null2String(jsonGzx.getString("ProbationaryPayroll"));
                        log.info("基本工资标准：" + strs1);
                        //基本工资标准
                        wrti[15] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[15].setFieldName("jbgz");
                        //wrti[15].setFieldValue(Util.null2String(jsonGzx.getString("basicSalary")));
                        //改为取大易的试用期工资
                        if (!"".equals(strs1)) {
                            wrti[15].setFieldValue(strs1);
                        }
                        wrti[15].setView(true);
                        wrti[15].setEdit(true);
                        wrti[15].setFieldOrder(0);
                        wrti[15].setMand(false);

                        //岗位津贴标准
                        wrti[16] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[16].setFieldName("gwjtbz");
                        //赋值
                        String strs2 = Util.null2String(jsonGzx.getString("Offergwjt"));
                        log.info("岗位津贴标准：" + strs2);
                        if (!"".equals(strs2)) {
                            wrti[16].setFieldValue(strs2);
                        }
                        wrti[16].setView(true);
                        wrti[16].setEdit(true);
                        wrti[16].setFieldOrder(0);
                        wrti[16].setMand(false);


                        //职能津贴-陈列
                        wrti[17] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[17].setFieldName("znjtcl");
                        //赋值
                        String strs3 = Util.null2String(jsonGzx.getString("offerznjtCL"));
                        log.info("职能津贴-陈列：" + strs3);
                        if (!"".equals(strs3)) {
                            wrti[17].setFieldValue(strs3);
                        }
                        wrti[17].setView(true);
                        wrti[17].setEdit(true);
                        wrti[17].setFieldOrder(0);
                        wrti[17].setMand(false);


                        //职能津贴-培训
                        wrti[18] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[18].setFieldName("znjtpx");
                        //赋值
                        String strs4 = Util.null2String(jsonGzx.getString("offerznjtPX"));
                        log.info("职能津贴-培训：" + strs4);
                        if (!"".equals(strs4)) {
                            wrti[18].setFieldValue(strs4);
                        }
                        wrti[18].setView(true);
                        wrti[18].setEdit(true);
                        wrti[18].setFieldOrder(0);
                        wrti[18].setMand(false);


                        //餐费标准
                        wrti[19] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[19].setFieldName("cfbz");
                        //赋值
                        String strs5 ="";
                        if(jsonGzx.has("MealSupplement")){
                            log.info("餐费标准mealSupplement存在时！");
                            strs5=Util.null2String(jsonGzx.getString("MealSupplement"));
                        }
                        log.info("餐费标准：" + strs5);
                        if (!"".equals(strs5)) {
                            wrti[19].setFieldValue(strs5);
                        }
                        wrti[19].setView(true);
                        wrti[19].setEdit(true);
                        wrti[19].setFieldOrder(0);
                        wrti[19].setMand(false);


                        //绩效工资标准
                        wrti[20] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[20].setFieldName("jxgz");
                        //赋值
                        String strs6 = Util.null2String(jsonGzx.getString("Offerjxgzbz"));
                        log.info("绩效工资标准：" + strs6);
                        if (!"".equals(strs6)) {
                            wrti[20].setFieldValue(strs6);
                        }
                        wrti[20].setView(true);
                        wrti[20].setEdit(true);
                        wrti[20].setFieldOrder(0);
                        wrti[20].setMand(false);


                        //零售体验奖标准=>改为月度表现奖基数标准(元/月)
                        wrti[21] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[21].setFieldName("lstyjbz");
                        //赋值
                        String strs7 = "";
                        if(jsonGzx.has("PerformanceA")){
                            log.info("月度表现奖基数标准(元/月)PerformanceA存在时！");
                            strs7=Util.null2String(jsonGzx.getString("PerformanceA"));
                        }
                        log.info("月度表现奖基数标准(元/月)：" + strs7);
                        if (!"".equals(strs7)) {
                            wrti[21].setFieldValue(strs7);
                        }
                        wrti[21].setView(true);
                        wrti[21].setEdit(true);
                        wrti[21].setFieldOrder(0);
                        wrti[21].setMand(false);

                        //月度奖金基数标准
                        wrti[22] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[22].setFieldName("ydjjjsbz");
                        //赋值
                        String strs8 = Util.null2String(jsonGzx.getString("Offerjxbz"));
                        log.info("月度奖金基数标准：" + strs8);
                        if (!"".equals(strs8)) {
                            wrti[22].setFieldValue(strs8);
                        }
                        wrti[22].setView(true);
                        wrti[22].setEdit(true);
                        wrti[22].setFieldOrder(0);
                        wrti[22].setMand(false);

                        //季度奖金基数标准
                        wrti[23] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[23].setFieldName("jdjjjsbz");
                        //赋值
                        String strs9 = Util.null2String(jsonGzx.getString("OfferJJJBZ"));
                        log.info("季度奖金基数标准：" + strs9);
                        if (!"".equals(strs9)) {
                            wrti[23].setFieldValue(strs9);
                        }
                        wrti[23].setView(true);
                        wrti[23].setEdit(true);
                        wrti[23].setFieldOrder(0);
                        wrti[23].setMand(false);


                        //半年度奖金基数标准
                        wrti[24] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[24].setFieldName("bndjjjsbz");
                        //赋值
                        String strs10 = Util.null2String(jsonGzx.getString("OfferBNJJBZ"));
                        log.info("半年度奖金基数标准：" + strs10);
                        if (!"".equals(strs10)) {
                            wrti[24].setFieldValue(strs10);
                        }
                        wrti[24].setView(true);
                        wrti[24].setEdit(true);
                        wrti[24].setFieldOrder(0);
                        wrti[24].setMand(false);


                        //年度奖金基数标准
                        wrti[25] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[25].setFieldName("nzjjjs");
                        //赋值
                        String strs11 = Util.null2String(jsonGzx.getString("annualBonus"));
                        log.info("年度奖金基数标准：" + strs11);
                        if (!"".equals(strs11)) {
                            wrti[25].setFieldValue(strs11);
                        }
                        wrti[25].setView(true);
                        wrti[25].setEdit(true);
                        wrti[25].setFieldOrder(0);
                        wrti[25].setMand(false);

                        //报销等级
                        wrti[26] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[26].setFieldName("bxjb");
                        log.info("报销等级：" + jsonGzx.getString("OfferBXDJ"));
                        String strBxjb = Util.null2String(jsonGzx.getString("OfferBXDJ"));
                        //查询报销级别对应值
                        rsHr.executeQuery("select id,bxjbdm from uf_bxjb where bxjbbm='" + strBxjb + "'");
                        rsHr.next();
                        log.info("报销级别大易:" + strBxjb + ",OA的id:" + rsHr.getString("id") + ";报销级别代码：" + rsHr.getString("bxjbdm"));
                        //赋值
                        wrti[26].setFieldValue(Util.null2String(rsHr.getString("id")));
                        wrti[26].setView(true);
                        wrti[26].setEdit(true);
                        wrti[26].setFieldOrder(0);
                        wrti[26].setMand(false);
                        //报销等级代码
                        wrti[27] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[27].setFieldName("bxjbdm");
                        log.info("报销等级代码:" + rsHr.getString("bxjbdm"));
                        wrti[27].setFieldValue(Util.null2String(rsHr.getString("bxjbdm")));
                        wrti[27].setView(true);
                        wrti[27].setEdit(true);
                        wrti[27].setFieldOrder(0);
                        wrti[27].setMand(false);

                        //税收居民类型 居民 0 非居民 1
                        wrti[28] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[28].setFieldName("ssyglx");
                        //检查证件号是否有值 赋值
                        if (strZjh.equals("null")) {
                            wrti[28].setFieldValue(Util.null2String(""));
                        } else {
                            wrti[28].setFieldValue("0");//居民
                        }
                        wrti[28].setView(true);
                        wrti[28].setEdit(true);
                        wrti[28].setFieldOrder(0);
                        wrti[28].setMand(false);

                        //零售体验奖基数标准(元/月)
                        wrti[29] = new WorkflowRequestTableField();
                        wrti[29].setFieldName("lstyjjsbz");
                        //赋值
                        String strs12 = Util.null2String(jsonGzx.getString("PerformanceAward"));
                        log.info("零售体验奖基数标准(元/月)" + strs12);
                        if (!"".equals(strs12)) {
                            wrti[29].setFieldValue(strs12);
                        }
                        wrti[29].setView(true);
                        wrti[29].setEdit(true);
                        wrti[29].setFieldOrder(0);
                        wrti[29].setMand(false);

                    }
                //endregion
                WorkflowRequestTableRecord[] wrtri = new WorkflowRequestTableRecord[1];
                wrtri[0] = new WorkflowRequestTableRecord();
                wrtri[0].setWorkflowRequestTableFields(wrti);
                WorkflowMainTableInfo wmi = new WorkflowMainTableInfo();
                wmi.setRequestRecords(wrtri);

                //共四个明细表
                //因为有四个明细表，数组长度为4
                WorkflowDetailTableInfo wdti[] = new WorkflowDetailTableInfo[5];



                //福利津贴明细表开始

                JSONObject jsonFljt = resumeJson.getJSONObject("offerInfo").getJSONObject("welfareInfo");
                //数据库操作
                RecordSet rsFl = new RecordSet();
                log.info("福利项:"+jsonFljt.toString());

                //查询福利津贴表建模表

                String strSql = "select * from uf_gzx";
                log.info("查询福利津贴:" + strSql);
                rsFl.executeQuery(strSql);
                log.info("返回长度:" + rsFl.getCounts());
                WorkflowRequestTableRecord[]   wrtriFl = new WorkflowRequestTableRecord[rsFl.getCounts()];
                int i = 0;
                    while (rsFl.next()) {
                        log.info("当前i的值:" + i);
                        log.info("进去福利津贴:" + rsFl.getString("id"));
                        wrti = new WorkflowRequestTableField[2];

                        wrti[0] = new WorkflowRequestTableField();
                        //字段在数据库中的字段名
                        wrti[0].setFieldName("gzfl");
                        //赋值
                        wrti[0].setFieldValue(Util.null2String(rsFl.getString("id")));
                        wrti[0].setView(true);
                        wrti[0].setEdit(true);

                        wrti[1] = new WorkflowRequestTableField();
                        //log.info("测试5:"+rsFl.getString("jkbm"));
                        //字段在数据库中的字段名
                        wrti[1].setFieldName("je");
                        String strValue = "";
                        if (jsonFljt != null && jsonFljt.size() != 0) {
                            strValue = jsonFljt.getString(rsFl.getString("jkbm"));
                            //赋值
                            log.info("查询福利津贴id:" + rsFl.getString("id") + ";各个值:" + strValue);
                        }

                        wrti[1].setFieldValue(Util.null2String(strValue));
                        wrti[1].setView(true);
                        wrti[1].setEdit(true);

                        wrtriFl[i] = new WorkflowRequestTableRecord();
                        wrtriFl[i].setWorkflowRequestTableFields(wrti);
                        i++;
                    }



                //明细表1
                //教育经历明细表数据 开始
                log.info("教育经历：" + educationJson.size());
                if (educationJson != null) {
                    log.info("educationJson.size()的长度" + educationJson.size());
                    DetailEducation detailEducation = new DetailEducation();
                    wrtri = detailEducation.detailEducation(educationJson);
                    wdti[0] = new WorkflowDetailTableInfo();
                    wdti[0].setWorkflowRequestTableRecords(wrtri);
//                    wdti[1] = new WorkflowDetailTableInfo();
//                    wdti[1].setWorkflowRequestTableRecords(wrtriFl);
                }
//                else{
//                    wdti[0] = new WorkflowDetailTableInfo();
//                    wdti[0].setWorkflowRequestTableRecords(wrtriFl);
//                }
                //教育经历明细表数据 结束

                //明细表2
                //工作经历明细表数据 开始
                log.info("工作经历：" + workingJsonarry.size());
                if (workingJsonarry != null) {
                    log.info("workingJsonarry.size()的长度" + workingJsonarry.size());
                    DetailWork detailWork = new DetailWork();
                    wrtri = detailWork.detailWork(workingJsonarry);
                    wdti[1] = new WorkflowDetailTableInfo();
                    wdti[1].setWorkflowRequestTableRecords(wrtri);
//                    wdti[2] = new WorkflowDetailTableInfo();
//                    wdti[2].setWorkflowRequestTableRecords(wrtriFl);
                }
//                else {
//                    wdti[0] = new WorkflowDetailTableInfo();
//                    wdti[0].setWorkflowRequestTableRecords(wrtri);
//                    wdti[1] = new WorkflowDetailTableInfo();
//                    wdti[1].setWorkflowRequestTableRecords(wrtriFl);
//                }
                //工作经历明细表数据 结束


//                if (educationJson != null && workingJsonarry != null) {
//                    log.info("进入当前值2:"+2);
//                    wdti[2] = new WorkflowDetailTableInfo();
//                    wdti[2].setWorkflowRequestTableRecords(wrtri);
//                }
//                if (educationJson == null && workingJsonarry != null) {
//                    log.info("进入当前值1:"+1);
//                    wdti[1] = new WorkflowDetailTableInfo();
//                    wdti[1].setWorkflowRequestTableRecords(wrtri);
//                }
//                if (educationJson != null && workingJsonarry == null) {
//                    log.info("进入当前值11:"+11);
//                    wdti[1] = new WorkflowDetailTableInfo();
//                    wdti[1].setWorkflowRequestTableRecords(wrtri);
//                }
//                if (educationJson == null && workingJsonarry == null) {
//                    log.info("进入当前值0:"+0);
//                    wdti[0] = new WorkflowDetailTableInfo();
//                    wdti[0].setWorkflowRequestTableRecords(wrtri);
//                }


                //明细表3
                //家庭成员明细表数据 开始
                log.info("家庭成员：" + familyJsonarry.size());
                if (familyJsonarry != null) {
                    log.info("familyJsonarry.size()的长度" + familyJsonarry.size());
                    DetailFamily detailFamily = new DetailFamily();
                    wrtri = detailFamily.detailFamily(familyJsonarry);

                    if (educationJson != null && workingJsonarry != null) {
                        log.info("家庭成员的明细顺序:"+3);
                        wdti[3] = new WorkflowDetailTableInfo();
                        wdti[3].setWorkflowRequestTableRecords(wrtri);
//                        wdti[3] = new WorkflowDetailTableInfo();
//                        wdti[3].setWorkflowRequestTableRecords(wrtriFl);
                    }
//                    if (educationJson == null && workingJsonarry != null) {
//                        log.info("家庭成员的明细顺序:"+2);
//                        wdti[1] = new WorkflowDetailTableInfo();
//                        wdti[1].setWorkflowRequestTableRecords(wrtri);
//                        wdti[2] = new WorkflowDetailTableInfo();
//                        wdti[2].setWorkflowRequestTableRecords(wrtriFl);
//                    }
//                    if (educationJson != null && workingJsonarry == null) {
//                        log.info("家庭成员的明细顺序22:"+22);
//                        wdti[1] = new WorkflowDetailTableInfo();
//                        wdti[1].setWorkflowRequestTableRecords(wrtri);
//                        wdti[2] = new WorkflowDetailTableInfo();
//                        wdti[2].setWorkflowRequestTableRecords(wrtriFl);
//                    }
//                    if (educationJson == null && workingJsonarry == null) {
//                        log.info("家庭成员的明细顺序1:"+1);
//                        wdti[0] = new WorkflowDetailTableInfo();
//                        wdti[0].setWorkflowRequestTableRecords(wrtri);
//                        wdti[1] = new WorkflowDetailTableInfo();
//                        wdti[1].setWorkflowRequestTableRecords(wrtriFl);
//                    }
                }
                //家庭成员明细表数据 结束
                       wdti[4] = new WorkflowDetailTableInfo();
                       wdti[4].setWorkflowRequestTableRecords(wrtriFl);

                //基本信息
                WorkflowBaseInfo wbi = new WorkflowBaseInfo();
                //表单的workflowid
                BaseBean baseBean = new BaseBean();
                //获取workflowid
                String propValue = baseBean.getPropValue("porturl", "formid");
                log.info("workflowid的值：" + propValue);
                wbi.setWorkflowId(propValue);

                WorkflowRequestInfo wri = new WorkflowRequestInfo();
                //todo 修改创建人
                String recruitUserName = Util.null2String(basicInfos.get("recruitUserName"));
                String hrSqlThree = "select * from uf_dylcjccf where zh = '" + recruitUserName + "'";
                log.info("查询流程创建人的sql：" + hrSqlThree);
                rsHrThree.executeQuery(hrSqlThree);
                String strCjr = "";
                if (rsHrThree.next()) {
                    strCjr = rsHrThree.getString("lccjr");
                } else {
                    //为空时，查询默认人
                    String strHrSqlFour = "select * from uf_dylcjccf where sfmr ='0'";
                    rsHrFour.executeQuery(strHrSqlFour);
                    if (rsHrFour.next()) {
                        strCjr = rsHrFour.getString("lccjr");
                    }
                }
                log.info("cjr:" + strCjr);
                wri.setCreatorId(strCjr);
                wri.setRequestLevel("0");//紧急程度
                wri.setRequestName("人员入职流程");//请求的名称
                //停留在提交节点
                wri.setIsnextflow("0");
                //主表数据
                wri.setWorkflowMainTableInfo(wmi);
                wri.setWorkflowBaseInfo(wbi);

                //明细表数据
                wri.setWorkflowDetailTableInfos(wdti);
                WorkflowServiceImpl wfsi = new WorkflowServiceImpl();
                //todo 修改创建人
                //获取简历信息中的hr

                String strHrSql = "select * from uf_dylcjccf where zh = '" + recruitUserName + "'";
                log.info("获取创建人的sql：" + strHrSql);
                rsHr.executeQuery(strHrSql);
                //生成流程的requestid
                String requestid = "";
                if (rsHr.next()) {
                    requestid = wfsi.doCreateWorkflowRequest(wri, Integer.parseInt(rsHr.getString("lccjr")));
                } else {
                    //为空时，查询默认人
                    String hrSqlTwo = "select * from uf_dylcjccf where sfmr ='0'";
                    rsHrTwo.executeQuery(hrSqlTwo);
                    if (rsHrTwo.next()) {
                        requestid = wfsi.doCreateWorkflowRequest(wri, Integer.parseInt(rsHrTwo.getString("lccjr")));
                    }
                }
                log.info("批量生成流程返回值=" + requestid);
                //String message = "生成流程requestid==" + requestid;
                //流程id转为int类型
                int reId = Integer.parseInt(requestid);
                if (reId > 0) {


                    //查询表中是否已存在有数据
                    String sqlFour = "select * from uf_hd  where jlid = '" + strApplyId + "'";
                    log.info("查询回调建模表中是否有数据的sql：" + sqlFour);
                    rsFour.execute(sqlFour);
                    if (!rsFour.next()) {
                        String sqlFive = "insert into uf_hd (jlid,lcid) values ('" + strApplyId + "','" + requestid + "')  ";
                        log.info("增加数据的sql：" + sqlFive);
                        rsFive.execute(sqlFive);
                    }
                }
                }catch (Exception ex){
                    log.info("程序异常,异常信息："+ex.toString());
                    break;
                }
            }

            //存放所有的applyid并用，分开
            sbuffApplyids.append(strApplyId + ",");

        }
        //调用回调方法
        log.info("调用回调方法的简历id:" + sbuffApplyids);
        CallBack.callBack(sbuffApplyids);


    }


}




